package nextoffer.Tencent2;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Four {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        while (t-- >0) {
            int n = in.nextInt();
            int flag = 0;
            String[] s = new String[n];
            Map<String ,Integer> map = new HashMap<>();
            for (int i = 0; i < n; i++) {
                s[i] = in.next();
                map.put(s[i], 1);
            }
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < s[i].length(); j++) {
                        String qq = s[i].substring(j) + s[i].substring(0,j);
                        if(map.getOrDefault(qq, 0) == 1) {
                            System.out.println("YES");
                            flag = 1;
                        }
                        if(flag == 1)break;
                }
                if(flag == 1)break;
            }
            if(flag == 0) System.out.println("NO");

        }
    }
}
